﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BAL
{
    public partial class DeliveryMain : Form
    {
        private LoginService.BarcodeJudgeServices bjs = new BAL.LoginService.BarcodeJudgeServices();
        public string DInterID = "";
        private string ID;

        public DeliveryMain()
        {
            InitializeComponent();
        }

        public DeliveryMain(string _ID)
        {
            InitializeComponent();
            this.ID = _ID;
        }

        //返回
        private void button2_Click(object sender, EventArgs e)
        {
            Main2 main = new Main2(this.ID);
            main.Show();
            this.Hide();
        }
        private void DeliveryMain_Load(object sender, EventArgs e)
        {
            DataGridStyle();
            BinData();
        }
        //获取数据
        private void BinData()
        {
            DataSet ds = bjs.GetDeliveryMain();
            DataTable dt = new DataTable();

            dt = ds.Tables[0];
            if (dt.Rows.Count <= 0)
            {
                return;
            }
            else
            {
                dataGrid1.DataSource = dt;
            }
        }
        //数据窗口样式
        public void DataGridStyle()
        {
            DataGridTableStyle dts = new DataGridTableStyle();
            dataGrid1.TableStyles.Clear();
            dts.MappingName = "DeliveryMain";

            DataGridTextBoxColumn cl1 = new DataGridTextBoxColumn();
            cl1.HeaderText = "序号";
            cl1.MappingName = "Num";
            cl1.Width = 40;
            dts.GridColumnStyles.Add(cl1);

            DataGridTextBoxColumn cl2 = new DataGridTextBoxColumn();
            cl2.HeaderText = "单号";
            cl2.MappingName = "DInterID";
            cl2.Width = 120;
            dts.GridColumnStyles.Add(cl2);

            DataGridTextBoxColumn cl3 = new DataGridTextBoxColumn();
            cl3.HeaderText = "开单时间";
            cl3.MappingName = "Fdate";
            cl3.Width = 80;
            dts.GridColumnStyles.Add(cl3);

            DataGridTextBoxColumn cl4 = new DataGridTextBoxColumn();
            cl4.HeaderText = "开单人";
            cl4.MappingName = "FBillerID";
            cl4.Width = 50;
            dts.GridColumnStyles.Add(cl4);

            dataGrid1.TableStyles.Add(dts);

        }

        //刷新
        private void button1_Click(object sender, EventArgs e)
        {
            DataGridStyle();
            BinData();
        }

        private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
        {
            DataGrid dataGrid1 = sender as DataGrid;
            int index = ((DataGrid)sender).CurrentCell.RowNumber;
            if (((DataTable)(dataGrid1.DataSource)).Rows.Count > 0)
            {
                ((DataGrid)sender).Select(index);
            }
            DInterID = ((DataTable)(dataGrid1.DataSource)).Rows[index][1].ToString();
        }
        //明细
        private void button4_Click(object sender, EventArgs e)
        {
            if (DInterID == null || DInterID == "")
            {
                MessageBox.Show("请选择订单！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                return;
            }

            Delivery del = new Delivery(DInterID,this.ID);
            del.Show();
            this.Hide();
        }
        //完成
        private void button3_Click(object sender, EventArgs e)
        {
            bool lb = false;

            if (DInterID == null || DInterID == "")
            {
                MessageBox.Show("请选择订单！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                return;
            }
            else
            {
                lb = bjs.FinishDeliveryMain(DInterID);
                if (lb)
                {
                    DataGridStyle();
                    BinData();
                }
                else
                {
                    MessageBox.Show("操作失败！", "警告！", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button3);
                    return;
                }
            }
        }       

    }
}